<%= javascript_include_tag "checkbox_update.js" -%>
<%= javascript_include_tag "variable_table_check.js" -%>
<%= stylesheet_link_tag 'survey_ul'%>
<%= stylesheet_link_tag 'faux_table'%>
<% form_tag :url => { :action => "add_to_cart"} do -%>
  <div class="show_basic" style="padding-right: 2em;">
    <% if !logged_in? -%>
      <h2>Welcome, guest. Browse the table, look at the variable metadata.  If you want to download any variables then you need to 
        <% if REGISTRATION_CLOSED -%>
          <%= link_to "Request Access", signup_url %>
        <% else -%>
          <%= link_to "Sign up", signup_url %>
        <% end -%>		
        <br/>Don't see what you want - try another search with different terms.  Or choose some different <%= link_to "surveys", surveys_url -%>
      </h2><br/>
    <% else -%>
      <h2>Browse the table, select some variables, look at the metadata and add them to your cart.  <br/><br/>Don't see what you want - try another search with different terms or different <%= link_to "surveys", surveys_url -%>.  You could also ask a <%= link_to "question in the forums", forums_url -%>.</h2><br/>
    <% end -%>
    <%#= render :partial => "total_vars" -%>
<br/>
    <div style="position:relative;background-color:#ACCBE0;padding-top:5px;padding-bottom:5px;padding-left:5px;width:100%;height:85px;">
      <div style="position: absolute; ;top:0.9em;left:1em">
        <%= hidden_field_tag 'previous_query', @survey_search_query %>
        <%= text_field_tag :survey_search_query, @survey_search_query,:onclick=>"javascript:$('survey_search_query').select();",:title=>@survey_search_query %>
				<%= image_tag( method_to_icon_filename("help"), :size => "25x25", :alt => "Search terms quick guide", :title=>"Search terms quick guide", :onclick => "showPopup('help_box'); return false;",:class=> "help_image") -%>
        <%= submit_tag 'Search selected surveys again', :name=>"_submit", :id => "search_variables_button",:onclick => "if (!checkNotEmpty('survey_search_query')) {return false;} else {Form.getInputs(this.form, null,'submit')[0].value = 'search';};" %>
      </div>
      <div style="position: absolute; bottom:-10em; left:26em;">
              <%= image_tag method_to_icon_filename("large-spinner"), :id => "doing_stuff_spinner", :alt=>"working...", :title=>"working...", :style => "display: none; vertical-align: middle;",:height => '64', :width => '64' -%>
      </div>
      <div style="position: absolute; bottom:3em; left:1em;">
        Add results to current table?
        <%= radio_button_tag 'add_results', 'yes', false -%>Yes
        <%= radio_button_tag 'add_results', 'no', true -%>No
      </div>
      <%= hidden_field_tag 'submit', 'add' -%>
      <% if @selected_surveys!=nil %>
        <% @selected_surveys.each do |val| -%>
          <%= hidden_field_tag "entry_ids[]", val -%>
        <% end -%>
      <% end -%>
<% if logged_in? -%>
      <div style="position: absolute; bottom:1em; right:1em;">
        <%= submit_to_remote '_submit', 'Add selected variables to cart', {:url=>{:action=> "add_to_cart"}, :before => "Form.getInputs(this.form, null,'submit')[0].value = 'add';Element.show('spinner')",:success => "Element.hide('spinner')"} -%>
      </div>
<% end -%>
<!-- This code used to be used for linking variables together, might be used again-->
      <!-- <div style="position: absolute; bottom:1em; right:1em;"> -->
        <%#= text_field_tag :link_variables_text, @link_reason %>
        <%#= submit_to_remote '_submit', 'Group selected variables', {:url=>{:action=> "add_to_cart"}, :before => "Form.getInputs(this.form, null,'submit')[0].value = 'link';Element.show('spinner')",:success => "Element.hide('spinner')"} -%>
  <%#= submit_tag 'Group selected variables',:name=>"_submit", :id => "link_variables_button",:onclick => "Form.getInputs(this.form, null,'submit')[0].value = 'link';" -%>
      <!-- </div> -->
      <br/>
      <div style="position: absolute; bottom:1em; left:1em;">
	      <div id="help_box" style="display: none; z-index: 100; position: absolute;">
            <%= render :partial=>"term_help_popup" %>
          </div>
	Select:
        <%= link_to_function 'All', "$$('input.variable_checkbox').each(function(checkbox) { checkbox.checked = true; });" %>
        ,&nbsp
        <%= link_to_function 'None', "$$('input.variable_checkbox').each(function(checkbox) { checkbox.checked = false; });" %>
        ,&nbsp
        <%= link_to_function 'Invert selection', "$$('input.variable_checkbox').each(function(checkbox) { if (checkbox.checked == true) {checkbox.checked = false;} else {checkbox.checked = true; } });" %>
        
      </div>
<!-- keeps all the hidden inputs which match search term to variables -->
<div id="search_tracker_div">
</div>
<% if logged_in? -%>
      <div id="cart_button" style="position: absolute; top:1em; right:1em;">
        <%= render :partial => "cart/button" -%>
      </div>
<% end -%>
    </div>
	<br/>
	<br/>
    <%= render :partial =>  "total_vars" %>

    <div id="table_header" class="faux_table_header_container">
      <%= render :partial => "table_header", :locals=>{:sorted_variables => @sorted_variables} -%>
    </div>
    <div id="table_container" class="faux_table_container">
      <%= render :partial => "table", :locals=>{:sorted_variables => @sorted_variables ,:lineage => false, :extract_lineage => false, :extract_id => nil} -%>
    </div>
  </div>
<% end -%>
<div style="clear: both;"></div>
<script type="text/javascript">
  document.observe('dom:loaded', function() {
    uncheckAll();
  });
</script>